package com.hl.web;


import com.hl.pojo.Courses;
import com.hl.service.CourseJianJieService;
import com.hl.util.GeneralResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController
@RequestMapping("/Course")
public class CourseJianJieController {
    @Autowired
    private CourseJianJieService courseJianJieService;
    @RequestMapping("/JianJie")
    public GeneralResult CourseJianJie(@RequestBody Map<String,Integer> map){
        Integer courseId = map.get("courseId");
        System.out.println(courseId);
        List<Courses> list = courseJianJieService.SelectCourseJianJie(courseId);
        System.out.println(list);
        return GeneralResult.success(list);
    }

    @RequestMapping("/JianJieVue")
    public GeneralResult CourseJianJieVue(){
        List<Courses> list = courseJianJieService.SelectCourseJianJieVue();
        System.out.println(list);
        return GeneralResult.success(list);
    }


    @RequestMapping("/JianJieDelete")
    public GeneralResult CourseJianJieDelete(@RequestBody  Map<String,Integer> id){
        Integer id1 = id.get("ClassID");
        Integer courses = courseJianJieService.CourseJianJieDelete(id1);
//        System.out.println(courses+"------------------------------");
        return GeneralResult.success("请求成功",courses);
    }

    @RequestMapping("/JianJieAdd")
    public GeneralResult CourseJianJieAdd(@RequestBody Map<String,Object> courses){

        String course_name = (String) courses.get("course_name");
        Integer course_duration = Integer.parseInt((String)courses.get("course_duration")) ;
        Integer slides_count= Integer.parseInt((String)courses.get("slides_count"));
        String  course_description = (String) courses.get("course_description");
        String  target_audience = (String) courses.get("target_audience");
        String  learning_outcomes = (String) courses.get("learning_outcomes");
        Integer consultant_id= Integer.parseInt((String)courses.get("consultant_id"));
        Double   price       =   Double.parseDouble((String)courses.get("price"));

        Courses courses1 = new Courses();

        courses1.setCourseName(course_name);
        courses1.setCourseDescription(course_description);
        courses1.setCourseDuration(course_duration);
        courses1.setSlidesCount(slides_count);
        courses1.setTargetAudience(target_audience);
        courses1.setLearningOutcomes(learning_outcomes);
        courses1.setConsultantId(consultant_id);
        courses1.setPrice(price);

         int coursesNum = courseJianJieService.CourseJianJieAdd(courses1);
        return GeneralResult.success("请求成功",coursesNum);
    }

    @RequestMapping("/JianJieUpdate")
    public  GeneralResult  CourseJianJieUpdate(@RequestBody Map<String,String> courses){

        Integer course_id2 = Integer.valueOf(courses.get("course_id"));
        String course_name2 =  courses.get("course_name");
        Integer course_duration2 = Integer.valueOf(courses.get("course_duration"));
        Integer slides_count2= Integer.valueOf(courses.get("slides_count"));
        String  course_description2 =  courses.get("course_description");
        String  target_audience2 =  courses.get("target_audience");
        String  learning_outcomes2 =  courses.get("learning_outcomes");
        Integer consultant_id2= Integer.valueOf(courses.get("consultant_id"));
//         Double doubleValue = Double.valueOf((String) obj);
        Double  price2   = Double.valueOf(courses.get("price"));

        Courses courses2 = new Courses();

        courses2.setCourseId(course_id2);
        courses2.setCourseName(course_name2);
        courses2.setCourseDescription(course_description2);
        courses2.setCourseDuration(course_duration2);
        courses2.setSlidesCount(slides_count2);
        courses2.setTargetAudience(target_audience2);
        courses2.setLearningOutcomes(learning_outcomes2);
        courses2.setConsultantId(consultant_id2);
        courses2.setPrice(price2);
//
        int coursesNum = courseJianJieService.CourseJianJieUpdate(courses2);
        return GeneralResult.success("请求成功",coursesNum);
    }
    @RequestMapping("/JianJieSearch")
    public GeneralResult CourseJianJieSearch(@RequestBody Map<String,String> courseName){

        String CourseName = courseName.get("course_name");
        System.out.println(CourseName);
        List<Courses> list = courseJianJieService.CourseJianJieSearch(CourseName);
        System.out.println(list);
        return GeneralResult.success("请求成功",list);
    }

}
